import os

import platform

# Done by HeKo, since i run the first tests for
# LM73 under windows it's necessary to load
# LM73Device successfully!
if platform.system() != "Windows":
    import fcntl

class I2CDevice(object):
    I2C_SLAVE = 0x0703 # from <linux/i2c-dev.h>
    def __init__(self, busno, addr, testCase = False):
        
        if testCase:
            return
    
        fd = os.open('/dev/i2c-%d' % busno, os.O_RDWR)
        fcntl.ioctl(fd, self.I2C_SLAVE, addr)
        self.__fd = fd
        pass
    def write(self, msg):
        os.write(self.__fd, msg)
        pass
    def read(self, n):
        msg = os.read(self.__fd, n)
        assert len(msg) == n
        return msg
    pass

